package com.learning.platform.repository;

import com.learning.platform.entity.ExamQuestion;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ExamQuestionRepository extends JpaRepository<ExamQuestion, Long> {
    
    /**
     * 查询考试的所有题目（按顺序）
     */
    List<ExamQuestion> findByExamIdOrderByOrderNoAsc(Long examId);
    
    /**
     * 统计考试题目数量
     */
    long countByExamId(Long examId);
    
    /**
     * 删除考试的所有题目
     */
    void deleteByExamId(Long examId);
    
    /**
     * 查询考试中的特定题目
     */
    ExamQuestion findByExamIdAndQuestionId(Long examId, Long questionId);
    
    /**
     * 获取考试题目的总分值
     */
    @Query("SELECT SUM(eq.points) FROM ExamQuestion eq WHERE eq.examId = :examId")
    Double getTotalPointsByExamId(@Param("examId") Long examId);
}